<script setup>
import { computed, reactive } from "vue";
import TreeMenu from "./treeMenu.vue";
import { useRouter } from "vue-router";
const router = useRouter();

// 将路由配置中的子路由数据转换为响应式对象
// 这里的目的是为了能够在组件中实时反映路由配置的变更
const menuData = reactive(router.options.routes[0].children);

//  引入状态管理
import { useMenuStore } from "../store/index"; // 从统一入口引入
const menuStore = useMenuStore();
// 获取侧边栏是否折叠的状态
const isCollapse = computed(() => menuStore.isCollapse);







const handleOpen = (key, keyPath) => {
  // console.log(key, keyPath);
};
const handleClose = (key, keyPath) => {
  // console.log(key, keyPath);
};
</script>

<template>
  <el-menu
    :style="{ width: !isCollapse ? '200px' : '64px' }"
    active-text-color="#ffd04b"
    background-color="#545c64"
    class="aside-container"
    default-active="2"
    text-color="#fff"
    :collapse="isCollapse"
    @open="handleOpen"
    @close="handleClose"
  >
    <!-- logo -->
    <p class="logo-lg">{{ isCollapse ? "DiDi" : "DiDi陪诊" }}</p>
    <!-- 菜单 -->
    <TreeMenu :index="1" :menuData="menuData" />
  </el-menu>
</template>

<style lang="less" scoped>
.aside-container {
  height: 100%;
  .logo-lg {
    text-align: center;
    font-size: 20px;
    height: 50px;
    color: #fff;
    line-height: 50px;
  }
}
</style>
